package com.wangjw.coreTechnology;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

/**
 * Created by wangjw on 18/7/19.
 */
public class ThreadDemo {

    public static void main(String[] args) {
        test1();
    }

    private static void test1() {
        Runnable task = () -> {
            System.out.println("Hello World!");
        };

        try {
            Thread thread = new Thread(task);
            thread.start();
            thread.join();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    private static void test2() {
        Runnable task = () -> {
            System.out.println("Hello World!");
        };

        try {
            Future future = Executors.newFixedThreadPool(1)
                    .submit(task);
            System.out.println(future.get());
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
    }

    private static void test3() {
        Thread daemonThread = new Thread();
        daemonThread.setDaemon(true);
        daemonThread.start();
    }
}
